package net.microfigure.controller;

import javax.validation.Valid;

import java.util.List;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import net.microfigure.commons.result.PageInfo;
import net.microfigure.model.IllCard;
import net.microfigure.service.IIllCardService;
import net.microfigure.commons.base.BaseController;

/**
 * <p>
 * 慢性病证表 前端控制器
 * </p>
 *
 * @author 林景锋
 * @since 2018-06-25
 */
@Controller
@RequestMapping("/illCard")
public class IllCardController extends BaseController {

    @Autowired private IIllCardService illCardService;
    
    @GetMapping("/manager")
    public String manager() {
        return "admin/illCard/familyCardfList";
    }

    
    
    @GetMapping("/dataGrid")
	@ResponseBody
	public Object dataGrid(Integer page,Integer rows,String sort, String order,String cardNo) {
		PageInfo pageInfo = new PageInfo(page, rows, sort, order);
		
		
		
		System.out.println("不废话打印");
		illCardService.selectDataGrid(pageInfo,cardNo);
		return pageInfo;


	}
    
    
    
    
    
    /**
     * 添加页面
     * @return
     */
    @GetMapping("/addPage")
    public String addPage(Model model, String cardNo) {
    	IllCard illCard = illCardService.perAddIllCard(cardNo);
		model.addAttribute("illCard", illCard); 	
        return "admin/illCard/illCardAdd";
    }
    
    /**
     * 添加
     * @param 
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public Object add(@Valid IllCard illCard ,Model model) {

         illCardService.registerIllCard(illCard);
       
            return renderSuccess("添加成功！");
      
    }
    
    /**
     * 删除
     * @param id
     * @return
     */
    @PostMapping("/delete")
    @ResponseBody
    public Object delete(Long id) {

         illCardService.deleteIllCard(id);
       
            return renderSuccess("删除成功！");
       
    }
    
    /**
     * 编辑
     * @param model
     * @param id
     * @return
     */
    @GetMapping("/editPage")
    public String editPage(Model model, Long id) {
        IllCard illCard = illCardService.selectById(id);
        model.addAttribute("illCard", illCard);
        return "admin/illCard/illCardEdit";
    }
    
    /**
     * 编辑
     * @param 
     * @return
     */
    @PostMapping("/edit")
    @ResponseBody
    public Object edit(@Valid IllCard illCard) {

        boolean b = illCardService.updateById(illCard);
        if (b) {
            return renderSuccess("编辑成功！");
        } else {
            return renderError("编辑失败！");
        }
    }
}
